using System.Collections;
using UnityEngine;

public class EnemyRemote : Enemy
{
    [SerializeField] private GameObject enemyBulletPrefab;
    protected override void OnEnable()
    {
        base.OnEnable();
        StartCoroutine(AttackCo());
    }

    private IEnumerator AttackCo()
    {
        while (gameObject.activeSelf)
        {
            isAttack = false;

            yield return attackWaitWFX;

            TriggerAttack();
        }
    }
    public override void HandlePlayerDead()
    {
        base.HandlePlayerDead();
        StopAllCoroutines();
    }
    private void TriggerAttack()
    {
        isAttack = true;
        Vector2 fireDir = (chaseTarget.position - transform.position).normalized;
        GameObject enemyBullet = PoolManager.Instance.Get(enemyBulletPrefab, (enemyBullet) =>
        {
            enemyBullet.transform.position = transform.position;
            enemyBullet.GetComponent<Object_EnemyBullet>().SetupBullet(fireDir, _enemyStat.GetAttackDamage());
        });
    }
}
